<?php
    //设置编码utf-8
    header("Content-type:text/html;charset=utf8");
    //输出学生的学号和名字
	if(isset($_POST["student_id"]) && isset($_POST["student_name"])){
          echo '学号:'.$_POST["student_id"];
		  echo '<br/>';
		  echo '名称:'.$_POST["student_name"];
		  echo '<br/>';
	}else{
		echo '错误';
		return;
	}
	//连接到数据库和数据库的密码用户名等;   
    $db_host="localhost";
    $db_user="root";
    $db_pw="";
    $db_name="my_bookmanager";
    $mysqli=new mysqli($db_host,$db_user,$db_pw,$db_name); 
    if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}
    $mysqli->set_charset('utf8');
	mysqli_query($mysqli,'SET NAMES UTF8');
    //获取在html页面的书籍信息
    $all_price=0;
    if(isset($_POST['text']) && count($_POST['text'])>0)
    {
    $book_info=$_POST['text'];
    $book_info_amount=count($book_info); 
    for($c=0;$c<$book_info_amount;$c++){
    	$price=$_POST['text'][$c]."<br/>";
    	$all_price=$all_price+$price;
    }
      	echo '订书总金额为'.$all_price.'元<br/>';
    }
    else
    {echo '订书总金额为0元<br/>';}
    if(mysqli_query($mysqli,"REPLACE into backmanager(student_name,student_id,ALL_BOOK_PRICE) value('{$_POST['student_name']}','{$_POST['student_id']}',$all_price)" ))
    {
    	echo "查询成功".'<br/>';
    }
    else 
    {   
        mysqli_error($mysqli); 
    	echo "查询失败.'<br/>'";
    }
 

?>




